
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>URLconfs 中使用的 django.urls 函数 &#8212; Django 3.2.11.dev 文档</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="Django 实用程序" href="utils.html" />
    <link rel="prev" title="django.urls 实用函数" href="urlresolvers.html" />



 
<script src="../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../index.html">Django 3.2.11.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../index.html">Home</a>  |
        <a title="Table of contents" href="../contents.html">Table of contents</a>  |
        <a title="Global index" href="../genindex.html">Index</a>  |
        <a title="Module index" href="../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="urlresolvers.html" title="&lt;code class=&#34;docutils literal notranslate&#34;&gt;&lt;span class=&#34;pre&#34;&gt;django.urls&lt;/span&gt;&lt;/code&gt; 实用函数">previous</a>
     |
    <a href="index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="utils.html" title="Django 实用程序">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-urls">
            
  <div class="section" id="s-module-django.urls.conf">
<span id="s-django-urls-functions-for-use-in-urlconfs"></span><span id="module-django.urls.conf"></span><span id="django-urls-functions-for-use-in-urlconfs"></span><h1>URLconfs 中使用的 <code class="docutils literal notranslate"><span class="pre">django.urls</span></code> 函数<a class="headerlink" href="#module-django.urls.conf" title="永久链接至标题">¶</a></h1>
<div class="section" id="s-path">
<span id="path"></span><h2><code class="docutils literal notranslate"><span class="pre">path()</span></code><a class="headerlink" href="#path" title="永久链接至标题">¶</a></h2>
<dl class="function">
<dt id="django.urls.path">
<code class="descname">path</code>(<em>route</em>, <em>view</em>, <em>kwargs=None</em>, <em>name=None</em>)<a class="headerlink" href="#django.urls.path" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>返回一个元素，以便包含在 <code class="docutils literal notranslate"><span class="pre">urlpatterns</span></code> 中。例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.urls</span> <span class="kn">import</span> <span class="n">include</span><span class="p">,</span> <span class="n">path</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="p">[</span>
    <span class="n">path</span><span class="p">(</span><span class="s1">&#39;index/&#39;</span><span class="p">,</span> <span class="n">views</span><span class="o">.</span><span class="n">index</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;main-view&#39;</span><span class="p">),</span>
    <span class="n">path</span><span class="p">(</span><span class="s1">&#39;bio/&lt;username&gt;/&#39;</span><span class="p">,</span> <span class="n">views</span><span class="o">.</span><span class="n">bio</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;bio&#39;</span><span class="p">),</span>
    <span class="n">path</span><span class="p">(</span><span class="s1">&#39;articles/&lt;slug:title&gt;/&#39;</span><span class="p">,</span> <span class="n">views</span><span class="o">.</span><span class="n">article</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;article-detail&#39;</span><span class="p">),</span>
    <span class="n">path</span><span class="p">(</span><span class="s1">&#39;articles/&lt;slug:title&gt;/&lt;int:section&gt;/&#39;</span><span class="p">,</span> <span class="n">views</span><span class="o">.</span><span class="n">section</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;article-section&#39;</span><span class="p">),</span>
    <span class="n">path</span><span class="p">(</span><span class="s1">&#39;weblog/&#39;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s1">&#39;blog.urls&#39;</span><span class="p">)),</span>
    <span class="o">...</span>
<span class="p">]</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">route</span></code> 参数应该是一个字符串或 <a class="reference internal" href="utils.html#django.utils.translation.gettext_lazy" title="django.utils.translation.gettext_lazy"><code class="xref py py-func docutils literal notranslate"><span class="pre">gettext_lazy()</span></code></a> （参见 <a class="reference internal" href="../topics/i18n/translation.html#translating-urlpatterns"><span class="std std-ref">翻译URL模式</span></a>），它包含一个 URL 模式。这个字符串可以包含角括号（就像上面的 <code class="docutils literal notranslate"><span class="pre">&lt;username&gt;</span></code>）来捕获 URL 的一部分，并将其作为关键字参数发送给视图。角括号可以包含一个转换器规格（像 <code class="docutils literal notranslate"><span class="pre">&lt;int:section&gt;</span></code> 的 <code class="docutils literal notranslate"><span class="pre">int</span></code> 部分），它限制了匹配的字符，也可以改变传递给视图的变量的类型。例如，<code class="docutils literal notranslate"><span class="pre">&lt;int:section&gt;</span></code> 匹配一串十进制数字，并将值转换为 <code class="docutils literal notranslate"><span class="pre">int</span></code>。更多细节请参见 <a class="reference internal" href="../topics/http/urls.html#how-django-processes-a-request"><span class="std std-ref">Django 如何处理一个请求</span></a>。</p>
<p><code class="docutils literal notranslate"><span class="pre">view</span></code> 参数是一个视图函数或 <a class="reference internal" href="class-based-views/base.html#django.views.generic.base.View.as_view" title="django.views.generic.base.View.as_view"><code class="xref py py-meth docutils literal notranslate"><span class="pre">as_view()</span></code></a> 的结果，用于基于类的视图。它也可以是一个 <a class="reference internal" href="#django.urls.include" title="django.urls.include"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.urls.include()</span></code></a>。</p>
<p><code class="docutils literal notranslate"><span class="pre">kwargs</span></code> 参数允许你向视图函数或方法传递附加参数。参见 <a class="reference internal" href="../topics/http/urls.html#views-extra-options"><span class="std std-ref">传递额外选项给视图函数</span></a> 的例子。</p>
<p>关于为什么 <code class="docutils literal notranslate"><span class="pre">name</span></code> 参数是有用的，请参见 <a class="reference internal" href="../topics/http/urls.html#naming-url-patterns"><span class="std std-ref">命名 URL 模式</span></a>。</p>
</div>
<div class="section" id="s-re-path">
<span id="re-path"></span><h2><code class="docutils literal notranslate"><span class="pre">re_path()</span></code><a class="headerlink" href="#re-path" title="永久链接至标题">¶</a></h2>
<dl class="function">
<dt id="django.urls.re_path">
<code class="descname">re_path</code>(<em>route</em>, <em>view</em>, <em>kwargs=None</em>, <em>name=None</em>)<a class="headerlink" href="#django.urls.re_path" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>返回一个元素，以便包含在 <code class="docutils literal notranslate"><span class="pre">urlpatterns</span></code> 中。例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.urls</span> <span class="kn">import</span> <span class="n">include</span><span class="p">,</span> <span class="n">re_path</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="p">[</span>
    <span class="n">re_path</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;^index/$&#39;</span><span class="p">,</span> <span class="n">views</span><span class="o">.</span><span class="n">index</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;index&#39;</span><span class="p">),</span>
    <span class="n">re_path</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;^bio/(?P&lt;username&gt;\w+)/$&#39;</span><span class="p">,</span> <span class="n">views</span><span class="o">.</span><span class="n">bio</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;bio&#39;</span><span class="p">),</span>
    <span class="n">re_path</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;^weblog/&#39;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s1">&#39;blog.urls&#39;</span><span class="p">)),</span>
    <span class="o">...</span>
<span class="p">]</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">route</span></code> 参数应该是一个字符串或 <a class="reference internal" href="utils.html#django.utils.translation.gettext_lazy" title="django.utils.translation.gettext_lazy"><code class="xref py py-func docutils literal notranslate"><span class="pre">gettext_lazy()</span></code></a> （参见 <a class="reference internal" href="../topics/i18n/translation.html#translating-urlpatterns"><span class="std std-ref">翻译URL模式</span></a>），它包含一个与 Python 的 <a class="reference external" href="https://docs.python.org/3/library/re.html#module-re" title="(在 Python v3.10)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a> 模块兼容的正则表达式。字符串通常使用原始字符串语法（<code class="docutils literal notranslate"><span class="pre">r''</span></code>），因此它们可以包含像 <code class="docutils literal notranslate"><span class="pre">/d</span></code> 这样的序列，而不需要用另一个反斜杠来转义。当进行匹配时，从正则表达式中捕获的组会被传递到视图中 —— 如果组是命名的，则作为命名的参数，否则作为位置参数。值以字符串的形式传递，不进行任何类型转换。</p>
<p><code class="docutils literal notranslate"><span class="pre">view</span></code>、<code class="docutils literal notranslate"><span class="pre">kwargs</span></code> 和 <code class="docutils literal notranslate"><span class="pre">name</span></code> 参数与 <a class="reference internal" href="#django.urls.path" title="django.urls.path"><code class="xref py py-func docutils literal notranslate"><span class="pre">path()</span></code></a> 相同。</p>
</div>
<div class="section" id="s-include">
<span id="include"></span><h2><code class="docutils literal notranslate"><span class="pre">include()</span></code><a class="headerlink" href="#include" title="永久链接至标题">¶</a></h2>
<dl class="function">
<dt id="django.urls.include">
<code class="descname">include</code>(<em>module</em>, <em>namespace=None</em>)<a class="headerlink" href="#django.urls.include" title="永久链接至目标">¶</a></dt>
<dt>
<code class="descname">include</code>(<em>pattern_list</em>)</dt>
<dt>
<code class="descname">include</code>(<em>(pattern_list</em>, <em>app_namespace)</em>, <em>namespace=None</em>)</dt>
<dd><p>一个函数，它接收一个完整的 Python 导入路径到另一个应该被 “包含” 在这里的 URLconf 模块。可以选择指定 <a class="reference internal" href="../topics/http/urls.html#term-application-namespace"><span class="xref std std-term">application namespace</span></a> 和 <a class="reference internal" href="../topics/http/urls.html#term-instance-namespace"><span class="xref std std-term">instance namespace</span></a>，在这两个空间中，条目将被包含进去。</p>
<p>通常，应用程序的命名空间应该由包含的模块指定。如果设置了应用程序命名空间，<code class="docutils literal notranslate"><span class="pre">namespace</span></code> 参数可以用来设置不同的实例命名空间。</p>
<p><code class="docutils literal notranslate"><span class="pre">include()</span></code> 也接受一个返回 URL 模式的迭代函数或一个包含这种迭代函数加上应用程序名称空间的二元元组作为参数。</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first last simple">
<li><strong>module</strong> -- URLconf 模块（或模块名称）</li>
<li><strong>namespace</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.10)"><em>str</em></a>) -- 包含的 URL 条目的实例命名空间。</li>
<li><strong>pattern_list</strong> -- 可迭代的 <a class="reference internal" href="#django.urls.path" title="django.urls.path"><code class="xref py py-func docutils literal notranslate"><span class="pre">path()</span></code></a> 和／或 <a class="reference internal" href="#django.urls.re_path" title="django.urls.re_path"><code class="xref py py-func docutils literal notranslate"><span class="pre">re_path()</span></code></a> 实例。</li>
<li><strong>app_namespace</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.10)"><em>str</em></a>) -- 被包含的 URL 条目的应用命名空间</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<p>参见 <a class="reference internal" href="../topics/http/urls.html#including-other-urlconfs"><span class="std std-ref">包含其它的URLconfs</span></a> 和 <a class="reference internal" href="../topics/http/urls.html#namespaces-and-include"><span class="std std-ref">URL 命名空间和包含的 URLconfs</span></a>。</p>
</div>
<div class="section" id="s-register-converter">
<span id="register-converter"></span><h2><code class="docutils literal notranslate"><span class="pre">register_converter()</span></code><a class="headerlink" href="#register-converter" title="永久链接至标题">¶</a></h2>
<dl class="function">
<dt id="django.urls.register_converter">
<code class="descname">register_converter</code>(<em>converter</em>, <em>type_name</em>)<a class="headerlink" href="#django.urls.register_converter" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>注册一个转换器的函数，用于 <a class="reference internal" href="#django.urls.path" title="django.urls.path"><code class="xref py py-func docutils literal notranslate"><span class="pre">path()</span></code></a> 的 <code class="docutils literal notranslate"><span class="pre">route</span></code>。</p>
<p><code class="docutils literal notranslate"><span class="pre">converter</span></code> 参数是一个转换器类，<code class="docutils literal notranslate"><span class="pre">type_name</span></code> 是路径模式中使用的转换器名称。参见 <a class="reference internal" href="../topics/http/urls.html#registering-custom-path-converters"><span class="std std-ref">注册自定义的路径转换器</span></a> 的例子。</p>
</div>
</div>
<div class="section" id="s-module-django.conf.urls">
<span id="s-django-conf-urls-functions-for-use-in-urlconfs"></span><span id="module-django.conf.urls"></span><span id="django-conf-urls-functions-for-use-in-urlconfs"></span><h1>URLconfs 中使用的 <code class="docutils literal notranslate"><span class="pre">django.conf.urls</span></code> 函数<a class="headerlink" href="#module-django.conf.urls" title="永久链接至标题">¶</a></h1>
<div class="section" id="s-static">
<span id="static"></span><h2><code class="docutils literal notranslate"><span class="pre">static()</span></code><a class="headerlink" href="#static" title="永久链接至标题">¶</a></h2>
<dl class="function">
<dt id="django.conf.urls.static.static">
<code class="descclassname">static.</code><code class="descname">static</code>(<em>prefix</em>, <em>view=django.views.static.serve</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.conf.urls.static.static" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>用于返回在调试模式下服务文件的 URL 模式的辅助函数：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf</span> <span class="kn">import</span> <span class="n">settings</span>
<span class="kn">from</span> <span class="nn">django.conf.urls.static</span> <span class="kn">import</span> <span class="n">static</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="p">[</span>
    <span class="c1"># ... the rest of your URLconf goes here ...</span>
<span class="p">]</span> <span class="o">+</span> <span class="n">static</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">MEDIA_URL</span><span class="p">,</span> <span class="n">document_root</span><span class="o">=</span><span class="n">settings</span><span class="o">.</span><span class="n">MEDIA_ROOT</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="s-url">
<span id="url"></span><h2><code class="docutils literal notranslate"><span class="pre">url()</span></code><a class="headerlink" href="#url" title="永久链接至标题">¶</a></h2>
<dl class="function">
<dt id="django.conf.urls.url">
<code class="descname">url</code>(<em>regex</em>, <em>view</em>, <em>kwargs=None</em>, <em>name=None</em>)<a class="headerlink" href="#django.conf.urls.url" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>这个函数是 <a class="reference internal" href="#django.urls.re_path" title="django.urls.re_path"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.urls.re_path()</span></code></a> 的别名。</p>
<div class="deprecated">
<p><span class="versionmodified">3.1 版后已移除: </span><a class="reference internal" href="#django.urls.re_path" title="django.urls.re_path"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.urls.re_path()</span></code></a> 的别名，以便向后兼容。</p>
</div>
</div>
<div class="section" id="s-handler400">
<span id="handler400"></span><h2><code class="docutils literal notranslate"><span class="pre">handler400</span></code><a class="headerlink" href="#handler400" title="永久链接至标题">¶</a></h2>
<dl class="data">
<dt id="django.conf.urls.handler400">
<code class="descname">handler400</code><a class="headerlink" href="#django.conf.urls.handler400" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>一个可调用对象，或者一个代表视图的完整 Python 导入路径的字符串，如果 HTTP 客户端发送了一个引起错误条件的请求，并且响应的状态码为 400，那么就会调用该视图。</p>
<p>默认情况下，这是 <a class="reference internal" href="views.html#django.views.defaults.bad_request" title="django.views.defaults.bad_request"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.views.defaults.bad_request()</span></code></a>。如果你实现了自定义视图，请确保它接受 <code class="docutils literal notranslate"><span class="pre">request</span></code> 和 <code class="docutils literal notranslate"><span class="pre">exception</span></code> 参数，并返回一个 <a class="reference internal" href="request-response.html#django.http.HttpResponseBadRequest" title="django.http.HttpResponseBadRequest"><code class="xref py py-class docutils literal notranslate"><span class="pre">HttpResponseBadRequest</span></code></a>。</p>
</div>
<div class="section" id="s-handler403">
<span id="handler403"></span><h2><code class="docutils literal notranslate"><span class="pre">handler403</span></code><a class="headerlink" href="#handler403" title="永久链接至标题">¶</a></h2>
<dl class="data">
<dt id="django.conf.urls.handler403">
<code class="descname">handler403</code><a class="headerlink" href="#django.conf.urls.handler403" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>一个可调用对象，或者一个代表视图的完整 Python 导入路径的字符串，如果用户没有访问资源所需的权限，那么就会调用该视图。</p>
<p>默认情况下，这是 <a class="reference internal" href="views.html#django.views.defaults.permission_denied" title="django.views.defaults.permission_denied"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.views.defaults.permission_denied()</span></code></a>。如果你实现了一个自定义视图，请确保它接受 <code class="docutils literal notranslate"><span class="pre">request</span></code> 和 <code class="docutils literal notranslate"><span class="pre">exception</span></code> 参数，并返回一个 <a class="reference internal" href="request-response.html#django.http.HttpResponseForbidden" title="django.http.HttpResponseForbidden"><code class="xref py py-class docutils literal notranslate"><span class="pre">HttpResponseForbidden</span></code></a>。</p>
</div>
<div class="section" id="s-handler404">
<span id="handler404"></span><h2><code class="docutils literal notranslate"><span class="pre">handler404</span></code><a class="headerlink" href="#handler404" title="永久链接至标题">¶</a></h2>
<dl class="data">
<dt id="django.conf.urls.handler404">
<code class="descname">handler404</code><a class="headerlink" href="#django.conf.urls.handler404" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>一个可调用对象，或者一个代表视图的完整 Python 导入路径的字符串，如果没有任何 URL 模式匹配，那么就会调用该视图。</p>
<p>默认情况下，这是 <a class="reference internal" href="views.html#django.views.defaults.page_not_found" title="django.views.defaults.page_not_found"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.views.defaults.page_not_found()</span></code></a>。如果你实现了自定义视图，请确保它接受 <code class="docutils literal notranslate"><span class="pre">request</span></code> 和 <code class="docutils literal notranslate"><span class="pre">exception</span></code> 参数，并返回一个 <a class="reference internal" href="request-response.html#django.http.HttpResponseNotFound" title="django.http.HttpResponseNotFound"><code class="xref py py-class docutils literal notranslate"><span class="pre">HttpResponseNotFound</span></code></a>。</p>
</div>
<div class="section" id="s-handler500">
<span id="handler500"></span><h2><code class="docutils literal notranslate"><span class="pre">handler500</span></code><a class="headerlink" href="#handler500" title="永久链接至标题">¶</a></h2>
<dl class="data">
<dt id="django.conf.urls.handler500">
<code class="descname">handler500</code><a class="headerlink" href="#django.conf.urls.handler500" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>一个可调用对象，或者一个代表视图的完整 Python 导入路径的字符串，在服务器出错时会被调用。当你在视图代码中出现运行时错误时，就会发生服务器错误。</p>
<p>默认情况下，这是 <a class="reference internal" href="views.html#django.views.defaults.server_error" title="django.views.defaults.server_error"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.views.defaults.server_error()</span></code></a>。如果你实现了自定义视图，请确保它接受一个 <code class="docutils literal notranslate"><span class="pre">request</span></code> 参数，并返回一个 <a class="reference internal" href="request-response.html#django.http.HttpResponseServerError" title="django.http.HttpResponseServerError"><code class="xref py py-class docutils literal notranslate"><span class="pre">HttpResponseServerError</span></code></a>。</p>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">URLconfs 中使用的 <code class="docutils literal notranslate"><span class="pre">django.urls</span></code> 函数</a><ul>
<li><a class="reference internal" href="#path"><code class="docutils literal notranslate"><span class="pre">path()</span></code></a></li>
<li><a class="reference internal" href="#re-path"><code class="docutils literal notranslate"><span class="pre">re_path()</span></code></a></li>
<li><a class="reference internal" href="#include"><code class="docutils literal notranslate"><span class="pre">include()</span></code></a></li>
<li><a class="reference internal" href="#register-converter"><code class="docutils literal notranslate"><span class="pre">register_converter()</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-django.conf.urls">URLconfs 中使用的 <code class="docutils literal notranslate"><span class="pre">django.conf.urls</span></code> 函数</a><ul>
<li><a class="reference internal" href="#static"><code class="docutils literal notranslate"><span class="pre">static()</span></code></a></li>
<li><a class="reference internal" href="#url"><code class="docutils literal notranslate"><span class="pre">url()</span></code></a></li>
<li><a class="reference internal" href="#handler400"><code class="docutils literal notranslate"><span class="pre">handler400</span></code></a></li>
<li><a class="reference internal" href="#handler403"><code class="docutils literal notranslate"><span class="pre">handler403</span></code></a></li>
<li><a class="reference internal" href="#handler404"><code class="docutils literal notranslate"><span class="pre">handler404</span></code></a></li>
<li><a class="reference internal" href="#handler500"><code class="docutils literal notranslate"><span class="pre">handler500</span></code></a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="urlresolvers.html"
                        title="上一章"><code class="docutils literal notranslate"><span class="pre">django.urls</span></code> 实用函数</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="utils.html"
                        title="下一章">Django 实用程序</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/ref/urls.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">12月 07, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="urlresolvers.html" title="&lt;code class=&#34;docutils literal notranslate&#34;&gt;&lt;span class=&#34;pre&#34;&gt;django.urls&lt;/span&gt;&lt;/code&gt; 实用函数">previous</a>
     |
    <a href="index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="utils.html" title="Django 实用程序">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>